//
//  VKMeJFSMController.m
//  V-Learn
//
//  Created by liubo on 2019/1/9.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "VKMeJFSMController.h"

@interface VKMeJFSMController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation VKMeJFSMController
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, LBNAVBAR_HEIGHT, ScreenW, ScreenH-LBNAVBAR_HEIGHT) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.scrollEnabled = NO;
        [_tableView  setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"积分说明";
    self.view.backgroundColor = [UIColor whiteColor];

    self.edgesForExtendedLayout = @[];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self setupUI];
}
- (void)setupUI{
    
    UILabel *titleLabel = [[UILabel alloc]init];
    [self.view addSubview:titleLabel];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.text = @"积分说明";
    titleLabel.font = [UIFont systemFontOfSize:17*ScaleX];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.mas_equalTo(self.view).offset(LBNAVBAR_HEIGHT - 30*ScaleX);
    }];
    
    UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn.backgroundColor = [UIColor clearColor];
    [self.view addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@12);
        make.width.height.equalTo(@40);
        make.centerY.equalTo(titleLabel);
    }];
    
    UIImageView *imageBackV = [[UIImageView alloc]init];
    [btn addSubview:imageBackV];
    imageBackV.image = [UIImage imageNamed:@"back"];
    imageBackV.contentMode = UIViewContentModeScaleAspectFill;
    imageBackV.userInteractionEnabled = NO;
    [imageBackV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(titleLabel);
        make.centerX.equalTo(btn);
    }];
    [btn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:self.tableView];
    self.tableView.rowHeight = 50;
    self.tableView.estimatedRowHeight = UITableViewAutomaticDimension;
    self.tableView.tableFooterView = [UIView new];
}
- (void)backAction{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
    NSArray *arr = @[@"登录App、每日签到、分享内容及邀请好友等操作都可以获取积分。获得的积分可以在积分商城中兑换优惠券礼品卡以及调调精选好物等礼品。具体的积分规则及获得方式如下:",@"连续签到第1天一第5天：每日签到积分+3，\n连续签到5天：额外获得15积分；\n连续签到第6天一第30天：每日签到积分+5，\n连续签到10天：额外获得20积分奖励；\n连续签到20天：额外获得50积分奖励；\n连续签到30天：额外获得100积分奖励；\n连续签到第31天及以上：每日签到积分+10；\n连续签到31天后特连续签到15天：额外100积分奖励；\n当连续签到中断后，则回到初始签到状态重新累计连续签到天数；\n邀请好友下载调调\n每邀请一名好友下载调调并成功输入你的道请码，你与好友均可获得积分+25\n当用户累计邀请5个好友的时候，可外获得50积分的奖励；当累计邀话10个好友的时候，可再获100积分的奖励；当邀请好友数超过10之后，每5个好友顾外奖50积分。",@"每天成功将调调内容分享到其他平台：每次央导积分3，最多3次。"];
    cell.textLabel.text = [arr objectAtIndex:indexPath.section];
    cell.textLabel.textColor = rgb(102, 102, 102);
    cell.textLabel.font = [UIFont systemFontOfSize:12];
    cell.textLabel.numberOfLines = 0;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *sectionView = [UIView new];
    UIImageView *icon = [[UIImageView alloc] init];
    icon.image = [UIImage imageNamed:@"wk_line"];
    [sectionView addSubview:icon];
    [icon makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.size.mas_equalTo(CGSizeMake(6, 22));
        make.centerY.mas_equalTo(sectionView);
    }];
    
    NSArray *arr = @[@"如何获取积分？",@"如何获取积分？",@"分享"];
    UILabel *label = [UILabel labelWithText:[arr objectAtIndex:section] andTextColor:rgb(51, 51, 51) andName:nil andFontSize:15];
    [sectionView addSubview:label];
    [label makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(icon.mas_right).mas_equalTo(5);
        make.centerY.mas_equalTo(sectionView);
    }];
    return sectionView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}
@end
